import request from '@/utils/requets'
import type { Get_C1_Data, SorN, Cate_Table, Cate_Data } from './type'

enum API {
    GET_C1 = '/admin/product/getCategory1/',
    GET_C2 = '/admin/product/getCategory2/',
    GET_C3 = '/admin/product/getCategory3/',
    BASECATE_URL = '/admin/product/attrInfoList/',
    SAVEINFO_URL = '/admin/product/saveAttrInfo',
    //删除某一个已有的属性
    DELETEATTR_URL = '/admin/product/deleteAttr/',
}
// 获取一级目录
export const getCategory1 = () => {
    return request.get<any, Get_C1_Data>(API.GET_C1)
}
// 二级
export const getCategory2 = (C1Id: SorN) => {
    return request.get<any, Get_C1_Data>(API.GET_C2 + C1Id)
}
// 三级
export const getCategory3 = (C2Id: SorN) => {
    return request.get<any, Get_C1_Data>(API.GET_C3 + C2Id)
}
// 获取属性
export const attrInfoList = (C1Id: SorN, C2Id: SorN, C3Id: SorN) => {
    return request.get<any, Cate_Table>(
        `${API.BASECATE_URL}${C1Id}/${C2Id}/${C3Id}`,
    )
}
// 添加或修改
export const saveAttrInfo = (data: Cate_Data) => {
    return request.post<any, Cate_Table>(API.SAVEINFO_URL, data)
}
// 删除
export const reqRemoveAttr = (attrId: number) =>
    request.delete<any, any>(API.DELETEATTR_URL + attrId)
